#   有 增加,删除,修改,查询学生姓名等功能,

#  encryption 可进入信息操作系统

#   添加信息 ,添加上方学生: 学号、年龄、性别、爱好

#   可在主操作系统界面更直观的用类似列表的形式来查询所有信息  <  all_information  >
#                也可选择  单个   或    部分          来 查询
#                  <select -- map>    <part_information -- filter>
import time

name = []
secrect_information = {}
information = []

def wait_time():
    time.sleep(1)

def decorator1(f):
    def inner():
        res = f()
        wait_time()
        return res
    return inner

def welcome():
    print('''Welcome to 学生操作系统V1版本
    查询操作请按1
    插入操作请按2
    删除操作请按3
    修改操作请按4
    list\'s information 指令:list
    退出信息操作界面输入:goout
    退出系统请输入over
    ''')

def find_name():
    global secrect_information
    global name
    print(name)

def input_insertname():
    global name
    insert_name = input('请输入要添加的姓名:')
    name.append(insert_name)
    print('插入操作成功!')

def input_removename():
    global name
    remove_name = input('请输入要删除的学生姓名:')
    if remove_name not in name:
        print(name)
        print('查无此人,请重新输入!!')
    name.remove(remove_name)
    print('删除操作成功!')

def input_changename():
    global name
    change_name1 = input('请输入被更改的学生姓名:')
    if change_name1 not in name:
        print('查无此人,请重新输入!!')
        print(name)
    change_name2 = name.index(change_name1)
    name.remove(change_name1)
    change_name3 = input('请输入要改的名:')
    name.insert(change_name2, change_name3)
    print('修改操作成功!')

def find_list_information():
    for i in secrect_information.items():
        print (i)

def encryption():
    print()
    print('✿✿ヽ(°▽°)ノ✿'*2)
    print()
    print('secret_information\n < 载入私密信息 :')
    print('退出信息操作指令:goout')
    print()
    print('原学生姓名列表:', name)

def input_information():
    global secrect_information
    while True:
        print('<注意学号不可重复>!!!')
        number = input('请输入学生要添加的学号:')
        if number == 'goout':
            print('已返回操作界面!')
            break
        print('原学生姓名列表:', name)
        a = input('请输入要添加上述学号的学生姓名:')
        if a not in name:
            print('\n无此姓名,请在下方选择\n')
            print('原学生姓名列表',name)
            print()
            continue
        print('请输入添加信息如下')
        insert_age = input('age:')
        insert_gender = input('gender:')
        insert_hobby = input('hobby')
        information = 'name:{},age:{},gender:{},hobby:{}'.format(a,insert_age,insert_gender,insert_hobby)
        secrect_information[number] = information
        print('添加信息操作成功如下!')
        print(secrect_information)

def decorator(fun):
    def inner():
        res = fun()
        input_information()
        return res
    return inner

def fun(n):
    return secrect_information[n]

def select():
    while True:
        n = input('请选择序号来查看相关信息:')
        if n == 'goout':
            print('已退回操作界面!')
            break
        if n not in secrect_information:
            print('无此序号,请在以下列表中选取')
            print(secrect_information.keys())
        else:
            list_information = map(fun, n)
            list_information = (list(list_information))
            print(list_information)

def part_information():
    print(secrect_information.keys())
    n = input('请选择学号起始范围:')
    y = input('终止范围不包括终点:')
    res = filter(lambda x:int(x) in range(int(n),int(y)),secrect_information)
    for i in res:
        print(i,fun(i))

def all_information():
    x = input('all全选\npart部分查看\nselect单独查看:')
    if x == 'all':
        return find_list_information()  # 遍历
    if x == 'select':
        return select()                 # map
    if x == 'part':
        part_information()              # filter

def inter_system():

    welcome()

    while True:
        a = input('请输入指令:')
        if a == '1':
            decorator1(find_name)()

        elif a == '2':
            decorator1(input_insertname)()

        elif a == '3':
            decorator1(input_removename)()

        elif a == '4':
            decorator1(input_changename)()

        elif a == 'encryption':
            decorator(encryption)()

        elif a == 'list':
            decorator1(all_information)()

        elif a == 'over':
            print('程序结束!')
            break
        else:
            print('无此指令及操作!')

inter_system()


